﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace ZEBuz.Questionnaire.Lib.Core
{
    public class CacheHelper
    {
        public const string CACHE_QuestionnaireUser_Seqno = "ZEBuz.QuestionnaireUser.Seqno.";

        public static T GetFromCache<T>(string cacheName) where T : new()
        {
            if (HttpContext.Current.Cache[cacheName] != null
                && HttpContext.Current.Cache[cacheName] is T)
            {
                return (T)HttpContext.Current.Cache[cacheName];
            }
            else
            {
                return default(T);
            }
        }

        public static void AddToCache<T>(string cacheName, T value)
        {
            if (HttpContext.Current.Cache[cacheName] != null)
            {
                HttpContext.Current.Cache[cacheName] = value;
            }
            else
            {
                HttpContext.Current.Cache.Add(cacheName, value,null,System.Web.Caching.Cache.NoAbsoluteExpiration,
                    System.Web.Caching.Cache.NoSlidingExpiration,System.Web.Caching.CacheItemPriority.Default,
                    null);

            }
        }
    }
}
